package com.vg.view;

import ce51.dunghn.imagethread.GVActivity;
import vg.com.chatonline.activity.R;
import vg.com.search_friend.SearchFriendsActivity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import br.com.dina.ui.widget.UITableView;
import br.com.dina.ui.widget.UITableView.ClickListener;

public class FindFriendFragment extends Fragment {

	private UITableView tableView, tableView2, tableView3;
	private static Fragment instace = null;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View vi = inflater.inflate(R.layout.main, null);
		tableView = (UITableView) vi.findViewById(R.id.tableView);
		tableView2 = (UITableView) vi.findViewById(R.id.tableView2);
		tableView3 = (UITableView) vi.findViewById(R.id.tableView3);

		createList();
		createList2();
		createList_Image_Friend();
		tableView.commit(R.layout.list_item_top, R.layout.list_item_bottom,
				R.layout.list_item_middle);
		tableView2.commit(R.layout.list_item_top, R.layout.list_item_bottom,
				R.layout.list_item_middle);
		tableView3.commit(R.layout.list_item_top, R.layout.list_item_bottom,
				R.layout.list_item_middle);
		return vi;
	}

	/* Kiem tra neu = null thi khoi tai lai Frame,neu k thi k can phai khoi tao */
	public static Fragment newinstance() {
		return new FindFriendFragment();
	}

	/*
	 * Tao ra cac Item cho UItableView
	 */
	private void createList() {
		CustomClickListener listener = new CustomClickListener();
		tableView.setClickListener(listener);
		tableView.addBasicItem(R.drawable.add_contact, "Thêm bạn", "");
		tableView.addBasicItem(R.drawable.add_user_goi_y, "Gợi Ý Thêm Bạn", "");

	}

	private void createList2() {
		tableView2.addBasicItem(R.drawable.add_user_goi_y, "Tìm Bạn", "");
		CustomClickListener2 listener2 = new CustomClickListener2();
		tableView2.setClickListener(listener2);
	}

	private void createList_Image_Friend() {
		tableView3.addBasicItem(R.drawable.add_user_goi_y, "Ảnh Cộng Đồng", "");
		CustomClickListener3 listener3 = new CustomClickListener3();
		tableView3.setClickListener(listener3);
	}

	// Set su kien khi click cac item cua cac UItableView
	public class CustomClickListener implements ClickListener {

		public void onClick(int index) {
			// TODO Auto-generated method stub
			if (index == 0) {
				Toast.makeText(getActivity(), "0", Toast.LENGTH_SHORT).show();
			} else if (index == 1) {
				Toast.makeText(getActivity(), "2", Toast.LENGTH_SHORT).show();
			}

		}

	}

	public class CustomClickListener2 implements ClickListener {

		public void onClick(int index) {
			// TODO Auto-generated method stub
			if (index == 0) {
				Intent i = new Intent(getActivity(),
						SearchFriendsActivity.class);
				startActivity(i);
			}
		}

	}

	public class CustomClickListener3 implements ClickListener {

		public void onClick(int index) {
			// TODO Auto-generated method stub
			if (index == 0) {
				Intent i = new Intent(getActivity(), GVActivity.class);
				startActivity(i);
			}
		}

	}

}
